﻿@{
    ViewBag.Title = "Home";
    Layout = "~/Views/Shared/_GridCommonLayout.cshtml";
}


<div class="row">
    <!--公告栏-->
    <article class="col-xs-12 col-sm-6 col-md-6 col-lg-6 sortable-grid">
        <div id="wid-id-2" class="jarviswidget jarviswidget-color-darken jarviswidget-sortable" data-widget-fullscreenbutton="false" data-widget-deletebutton="false" data-widget-colorbutton="false" data-widget-editbutton="false" style="" role="widget">
            <header role="heading">
                <span class="widget-icon">
                    <i class="fa fa-volume-up "></i>
                </span>
                <h2 class="font-md">
                    <strong>最新公告</strong>

                </h2>
                <h2 class="font-md" style="float: right">
                    <a href="/SysManger/Notices">更多>></a>
                </h2>
                <span class="jarviswidget-loader" style="display: none;">
                    <i class="fa fa-refresh fa-spin"></i>
                </span>
            </header>
            <div role="content" style="height:500px">
                <table class="table table-hover" style="margin-top: 30px;">
                    <tr>
                        <th >主题</th>
                        <th class="center">发件时间</th>
                        <th>发件人</th>
                    </tr>
                    <tbody data-bind="foreach:notices">
                        <tr data-bind="click: $root.showUpdateModal">
                            <td><a href="#myModal" role="button" style="color:black;text-decoration:underline;" 
                                data-toggle="modal" data-bind="text: STitle,click:$root.noticeView"></a></td>
                            <td data-bind="text: date(DSendtime)" class="center"></td>
                            <td data-bind="text: SSenderName"></td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>



    </article>
    <article class="col-xs-12 col-sm-6 col-md-6 col-lg-6 sortable-grid">

        <!--未读邮件-->
        <div id="wid-id-3" class="jarviswidget jarviswidget-color-darken jarviswidget-sortable" data-widget-fullscreenbutton="false" data-widget-deletebutton="false" data-widget-colorbutton="false" data-widget-editbutton="false" style="" role="widget">
            <header role="heading">
                <span class="widget-icon">
                    <i class="fa  fa-envelope  "></i>
                </span>
                <h2 class="font-md">
                    <strong>未读邮件</strong> （<i data-bind="text:noRead"></i> 封）

                </h2>
                <h2 class="font-md" style="float: right">
                    <a href="/Common/Email">更多>></a>
                </h2>
                <span class="jarviswidget-loader" style="display: none;">
                    <i class="fa fa-refresh fa-spin"></i>
                </span>
            </header>

            <div role="content" style="height:500px">
                <table class="table table-hover" style="margin-top: 30px;">
                    <tr>
                        <th>发件人</th>
                        <th style="width:200px" class="center">主题</th>
                        <th class="center">发件时间</th>
                    </tr>
                    <tbody data-bind="foreach:emails">

                        <tr>
                            <td><a data-bind="click:$root.jump,text: SSenderName" style="color: black;"></a></td>
                            <td class="center"><a data-bind="click:$root.jump,text: STitle" style="color: black;"></a></td>
                            <td data-bind="text: date(DSendtime)" class="center"></td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </article>
</div>



<div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="SysUserMessageModalLabel" aria-hidden="true">
    <div class="modal-header" style="background-color:white;">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>       
        <h3 id="myModalLabel" data-bind="text:title"></h3>
    </div>
    <div class="modal-body" style="background-color:white;height:200px;">
        <p data-bind="html:content"></p>
    </div>
    <div class="modal-footer"  style="margin-top:0px">
        <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
    </div>
</div>

<script type="text/javascript">
    function MyViewModel() {
        var self = this;
        self.notices = ko.observableArray();
        self.emails = ko.observableArray();
        self.content = ko.observable();
        self.title = ko.observable();
        self.noRead = ko.observable();
        self.noticeView = function (data) {
            $.ajax({
                url: "/Api/Common/SearchNotice",
                type: "POST",
                data: { id: data.Id }
            }).done(function (data) {
                self.title(data.title);
                self.content(data.content);

            })
        }
        self.jump = function (data) {
            window.location.href = "/Common/Email?email=" + data.Id;
        }
    }

    //规范时间显示格式
    function date(date) {
        if (date == "" || date == null)
            return "";
        var dd = date.slice(0, 10);
        var ss = date.slice(11, 19);
        return dd + " " + ss;
    }
    $(function () {
        var Model = new MyViewModel();

        $.ajax({
            url: "/Api/SysUser/Search",
            type: "POST"
        }).done(function (data) {
            Model.notices(data.notices);
            Model.emails(data.emails);
            Model.noRead(data.noRead);
        })

        ko.applyBindings(Model);
    })

   

</script>

   